In this part of the course, we will cover the following concepts:
highcharter| Objective | Complete |
|---|---|
| Install the highcharter package and discuss its application to build interactive visualizations | |
| Create a scatterplot using highcharter with tidy data |
highcharterHighcharter is an R wrapper that allows R users to tap into one of the most comprehensive data visualization JavaScript-based libraries
Though free for individual research and non-profit purposes, there are some restrictions
You may need a license to integrate it into a software or organization-wide products
For more information, refer to Highcharter’s website
highcharterhighchart() functionhchart() vs highchart()hchart is a shorthand version of the highchart function?hchart
hchart(Some_data, #<- dataset to use
"plot_type", #<- plot type to use
hcaes(x = variable1, #<- x-axis mapping
y = variable2, #<- y-axis mapping
group = variable3, #<- group by
...)) scatter, bar, column, line, etc.)hcaes (i.e., highchart aesthetics) for mapping variables as layers (just as with ggplot2)| Highcharter series type | Plot type |
|---|---|
scatter
|
scatterplot |
line
|
line graph |
boxplot
|
boxplot |
column
|
bar plot |
bar
|
horizontal bar plot |
histogram
|
histogram |
area
|
density |
| Objective | Complete |
|---|---|
| Install the highcharter package and discuss its application to build interactive visualizations |
✔ |
| Create a scatterplot using highcharter with tidy data |
In order to maximize the efficiency of your workflow, use the box package and encode your directory structure into variables
Let the main_dir be the variable corresponding to your materials folder
data directory inside the materials folder in your environment; hence we will save their path to a data_dir variableplots directory corresponding to plot_dir variablepaste0 command and pass the strings you would like to paste togetherhealthcare-dataset-stroke-dataThe dataset has 12 characteristics (columns), of which:
data_dir into R’s environment and subset itIn this module, we will explore a dataset subset, including the following variables:
bmi into a numeric column followed by imputing the missing values with the mean# Prep data for scatterplot
HDS_subset_long = HDS_subset %>%
gather(-age, #<- gather all variables but `age`
key = "variable",
value = "value") %>%
# All other transformations we've done before.
group_by(variable) %>%
mutate(norm_value = value/mean(value, na.rm = TRUE))
head(HDS_subset_long)# A tibble: 6 x 4
# Groups: variable [1]
age variable value norm_value
<dbl> <chr> <dbl> <dbl>
1 67 bmi 36.6 1.27
2 61 bmi 28.9 1
3 80 bmi 32.5 1.12
4 49 bmi 34.4 1.19
5 79 bmi 24 0.831
6 81 bmi 29 1.00
hcharthchart() function and pass the data, plot type (scatter), and aesthetics to it as arguments# Construct an interactive scatterplot.
scatter_interactive = #<- name the plot
hchart(HDS_subset_long, #<- set data
"scatter", #<- plot type "scatter"
hcaes(x = norm_value, #<- set aesthetics to map x-axis
y = age, #<- set aesthetics to map y-axis
group = variable)) #<- group byViewer pane, right next to the Help tabhchart (cont’d)hchart() detects more than one category, it auto-colors by series(%>%)hc_chart() function also controls global chart options like zoom, size, and themezoomType argument to hc_chart()
xy zoom allows zooming across both x and y axesYou are now ready to try tasks 1-4 in the Exercise for this topic
| Objective | Complete |
|---|---|
| Install the highcharter package and discuss its application to build interactive visualizations |
✔ |
| Create a scatterplot using highcharter with tidy data |
✔ |
In this part of the course, we have covered:
highcharter